package leecode

type MyQueue struct {
	input  []int //入栈
	output []int //出栈
}

func Constructor232() MyQueue {
	return MyQueue{
		input:  make([]int, 0),
		output: make([]int, 0),
	}
}

func (this *MyQueue) Push(x int) {
	this.input = append(this.input, x)
}

func (this *MyQueue) Pop() int {
	var result int
	//首先判断输出栈是否为空
	if len(this.output) == 0 {
		if len(this.input) == 0 {
			return -1
		}
		//将入栈的数据全部导入进 出栈
		for i := len(this.input) - 1; i >= 0; i-- {
			this.output = append(this.output, this.input[i])
		}
		//清空输入栈
		this.input = []int{}
	}
	result = this.output[len(this.output)-1]
	this.output = this.output[:len(this.output)-1]
	return result
}

func (this *MyQueue) Peek() int {
	result := this.Pop()
	if result == -1 {
		return result
	}
	this.output = append(this.output, result)
	return result
}

func (this *MyQueue) Empty() bool {
	return len(this.output) == 0 && len(this.input) == 0
}
